/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.VideologMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.secondpart.entity.VideologEntity;

import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class VideologMapperImpl {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.VideologMapper.selectAll
    
    public List<VideologEntity> selectAll(String ytenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from isv_videolog where  `dr`=0 and ytenant_id=?\n";
        parameter.addParam(ytenant_id);

        ResultSetProcessor processor = new AutoBeanListProcessor(new VideologEntity());
        return (List<VideologEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.VideologMapper.selectByIds
    
    public List<VideologEntity> selectByIds(List<String> strList) {
		if (strList==null || strList.size()==0) return new ArrayList<>();
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" select * from isv_videolog where `id` in ");
		if (CollectionUtil.isNotEmpty(strList)) {
			sqlBuilder.append(" ( ");
			String separator0 = " , ";
			for (int index = 0; index < strList.size(); index++) {
				String item = strList.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < strList.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}
		sqlBuilder.append(" and dr=0; ");

        
        String sql = sqlBuilder.toString();
        ResultSetProcessor processor = new AutoBeanListProcessor(new VideologEntity());
        return (List<VideologEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.VideologMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(VideologEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update isv_videolog set `name` = ?, `type` = ?, `status` = ?, `dr` = ?, `version` = ?, `create_time` = ?, `creator` = ?, `creatorName` = ?, `modify_time` = ?, `modifier` = ?, `modifierName` = ?, `pubts` = ? where `id` = ? and `ytenant_id` = ?\n";
        parameter.addParamWithType(record.getName(), Types.VARCHAR);
		parameter.addParamWithType(record.getType(), Types.INTEGER);
		parameter.addParamWithType(record.getStatus(), Types.INTEGER);
		parameter.addParamWithType(record.getDr(), Types.SMALLINT);
		parameter.addParamWithType(record.getVersion(), Types.INTEGER);
		parameter.addParamWithType(record.getCreate_time(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreatorName(), Types.VARCHAR);
		parameter.addParamWithType(record.getModify_time(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifierName(), Types.VARCHAR);
		parameter.addParamWithType(record.getPubts(), Types.TIMESTAMP);
		parameter.addParamWithType(record.getId(), Types.BIGINT);
		parameter.addParamWithType(record.getYtenant_id(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.VideologMapper.deleteByPrimaryKeys
    
    public int deleteByPrimaryKeys(List<Long> ids) {
		if (ids == null || ids.size()==0) return 0;
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" update isv_videolog set `dr` = 1 where `id` in ( ");
		if (CollectionUtil.isNotEmpty(ids)) {
			String separator0 = " , ";
			for (int i = 0; i < ids.size(); i++) {
				Long item = ids.get(i);
				sqlBuilder.append(" ? ");
				parameter.addParamWithType(item, Types.BIGINT);
				if (i < ids.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.VideologMapper.insert
    
    public int insert(VideologEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into isv_videolog (`id`, `name`,  `type`, `status`, `dr`,  `ytenant_id`, `version`, `create_time`,  `creator`, `creatorName`,  `modify_time`, `modifier`, `modifierName`,  `pubts`) values (?, ?,  ?, ?, ?,  ?, ?, ?,  ?, ?,  ?, ?, ?,  ?)\n";
        parameter.addParamWithType(record.getId(), Types.BIGINT);
		parameter.addParamWithType(record.getName(), Types.VARCHAR);
		parameter.addParamWithType(record.getType(), Types.INTEGER);
		parameter.addParamWithType(record.getStatus(), Types.INTEGER);
		parameter.addParamWithType(record.getDr(), Types.SMALLINT);
		parameter.addParamWithType(record.getYtenant_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getVersion(), Types.INTEGER);
		parameter.addParamWithType(record.getCreate_time(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreatorName(), Types.VARCHAR);
		parameter.addParamWithType(record.getModify_time(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifierName(), Types.VARCHAR);
		parameter.addParamWithType(record.getPubts(), Types.TIMESTAMP);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.VideologMapper.selectCount
    
    public int selectCount(String id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select count(1) from isv_videolog where `id`=? and dr=0;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new ColumnProcessor(int.class);
        return (int) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.VideologMapper.insertBatch
    
    public int insertBatch(List<VideologEntity> insertBatch) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into isv_videolog (`id`, `name`, `type`, `status`, `dr`, `ytenant_id`, `version`, `create_time`, `creator`, `creatorName`, `modify_time`, `modifier`, `modifierName`, `pubts`,`url`,`begintime`,`endtime`,`orderCode`,`moduleName`,`operators`,`deviceCode`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				VideologEntity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.BIGINT);
				parameter.addParamWithType(item.getName(), Types.VARCHAR);
				parameter.addParamWithType(item.getType(), Types.INTEGER);
				parameter.addParamWithType(item.getStatus(), Types.INTEGER);
				parameter.addParamWithType(item.getDr(), Types.SMALLINT);
				parameter.addParamWithType(item.getYtenant_id(), Types.VARCHAR);
				parameter.addParamWithType(item.getVersion(), Types.INTEGER);
				parameter.addParamWithType(item.getCreate_time(), Types.TIMESTAMP);
				parameter.addParamWithType(item.getCreator(), Types.VARCHAR);
				parameter.addParamWithType(item.getCreatorName(), Types.VARCHAR);
				parameter.addParamWithType(item.getModify_time(), Types.TIMESTAMP);
				parameter.addParamWithType(item.getModifier(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifierName(), Types.VARCHAR);
				parameter.addParamWithType(item.getPubts(), Types.TIMESTAMP);
				parameter.addParamWithType(item.getUrl(), Types.VARCHAR);
				parameter.addParamWithType(item.getBegintime(), Types.TIMESTAMP);
				parameter.addParamWithType(item.getEndtime(), Types.TIMESTAMP);
				parameter.addParamWithType(item.getOrderCode(), Types.VARCHAR);
				parameter.addParamWithType(item.getModuleName(), Types.VARCHAR);
				parameter.addParamWithType(item.getOperators(), Types.VARCHAR);
				parameter.addParamWithType(item.getDeviceCode(), Types.VARCHAR);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE name=VALUES(name),type=VALUES(type),status=VALUES(status),orgId=VALUES(orgId) ,modify_time=VALUES(modify_time),modifierName=VALUES(modifierName),modifier=VALUES(modifier) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.VideologMapper.selectById
    
    public VideologEntity selectById(String id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from isv_videolog where `id`=? limit 1;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new AutoBeanProcessor(new VideologEntity());
        return (VideologEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.VideologMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(Long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from isv_videolog where `id` = ?\n";
        parameter.addParamWithType(id, Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

}
